﻿﻿<template>
    <el-card class="form-container">
        <el-form :model="dataForm" ref="dataForm" :rules="dataRule"  @keyup.enter.native="dataFormSubmitHandle()" label-width="90px">
                                                                            <el-form-item label="行政区划代码" prop="regionCode">
                        <el-input v-model="dataForm.regionCode" placeholder="请输入行政区划代码"></el-input>
                    </el-form-item>
                                                                <el-form-item label="父级id" prop="parentCode">
                        <el-input v-model="dataForm.parentCode" placeholder="请输入父级id"></el-input>
                    </el-form-item>
                                                                <el-form-item label="地区名称" prop="regionName">
                        <el-input v-model="dataForm.regionName" placeholder="请输入地区名称"></el-input>
                    </el-form-item>
                                                                <el-form-item label="层级" prop="regionLevel">
                        <el-input v-model="dataForm.regionLevel" placeholder="请输入层级"></el-input>
                    </el-form-item>
                                                                <el-form-item label="排序号,1:省级,2:地市,3:区县" prop="regionSort">
                        <el-input v-model="dataForm.regionSort" placeholder="请输入排序号,1:省级,2:地市,3:区县"></el-input>
                    </el-form-item>
                                                                <el-form-item label="显示,1:显示,0:隐藏" prop="regionStatus">
                        <el-input v-model="dataForm.regionStatus" placeholder="请输入显示,1:显示,0:隐藏"></el-input>
                    </el-form-item>
                                                                <el-form-item label="备注" prop="regionRemark">
                        <el-input v-model="dataForm.regionRemark" placeholder="请输入备注"></el-input>
                    </el-form-item>
                                                                <el-form-item label="创建时间" prop="createTime">
                        <el-input v-model="dataForm.createTime" placeholder="请输入创建时间"></el-input>
                    </el-form-item>
                                                                <el-form-item label="修改时间" prop="updateTime">
                        <el-input v-model="dataForm.updateTime" placeholder="请输入修改时间"></el-input>
                    </el-form-item>
                                        <el-form-item>
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary"  @click="submit('dataForm')">确定</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</template>

<script>
    import {createRegion} from '@/api/admin/region'
    export default{
        name: 'add-region',
        data(){
            return {
                dataForm: {
                                                                                                                    regionCode : ''
                                                                                                parentCode : ''
                                                                                                regionName : ''
                                                                                                regionLevel : ''
                                                                                                regionSort : ''
                                                                                                regionStatus : ''
                                                                                                regionRemark : ''
                                                                                                createTime : ''
                                                                                                updateTime : ''
                                                            },
                dataRule: {
                                                                                                                    regionCode: [
                            {
                                required: true,
                                message: '请输入行政区划代码',
                                trigger: 'blur'
                            },
                            {
                                min: 3,
                                max: 20,
                                message: '长度在 3 到 20 个字符',
                                trigger: 'blur'
                            }
                        ]
                                                                                                parentCode: [
                            {
                                required: true,
                                message: '请输入父级id',
                                trigger: 'blur'
                            },
                            {
                                min: 3,
                                max: 20,
                                message: '长度在 3 到 20 个字符',
                                trigger: 'blur'
                            }
                        ]
                                                                                                regionName: [
                            {
                                required: true,
                                message: '请输入地区名称',
                                trigger: 'blur'
                            },
                            {
                                min: 3,
                                max: 20,
                                message: '长度在 3 到 20 个字符',
                                trigger: 'blur'
                            }
                        ]
                                                                                                regionLevel: [
                            {
                                required: true,
                                message: '请输入层级',
                                trigger: 'blur'
                            },
                            {
                                min: 3,
                                max: 20,
                                message: '长度在 3 到 20 个字符',
                                trigger: 'blur'
                            }
                        ]
                                                                                                regionSort: [
                            {
                                required: true,
                                message: '请输入排序号,1:省级,2:地市,3:区县',
                                trigger: 'blur'
                            },
                            {
                                min: 3,
                                max: 20,
                                message: '长度在 3 到 20 个字符',
                                trigger: 'blur'
                            }
                        ]
                                                                                                regionStatus: [
                            {
                                required: true,
                                message: '请输入显示,1:显示,0:隐藏',
                                trigger: 'blur'
                            },
                            {
                                min: 3,
                                max: 20,
                                message: '长度在 3 到 20 个字符',
                                trigger: 'blur'
                            }
                        ]
                                                                                                regionRemark: [
                            {
                                required: true,
                                message: '请输入备注',
                                trigger: 'blur'
                            },
                            {
                                min: 3,
                                max: 20,
                                message: '长度在 3 到 20 个字符',
                                trigger: 'blur'
                            }
                        ]
                                                                                                createTime: [
                            {
                                required: true,
                                message: '请输入创建时间',
                                trigger: 'blur'
                            },
                            {
                                min: 3,
                                max: 20,
                                message: '长度在 3 到 20 个字符',
                                trigger: 'blur'
                            }
                        ]
                                                                                                updateTime: [
                            {
                                required: true,
                                message: '请输入修改时间',
                                trigger: 'blur'
                            },
                            {
                                min: 3,
                                max: 20,
                                message: '长度在 3 到 20 个字符',
                                trigger: 'blur'
                            }
                        ]
                                                            }
            }
        },
        methods:{
            cancel(){
                this.$router.go(-1)
            },
            submit(){
                const set = this.$refs;
                set['dataForm'].validate((valid) => {
                    if (!valid) {
                        return false
                    }
                    createRegion(this.dataForm).then(() => {
                        this.$notify({
                            title: '添加成功',
                            message: '添加成功',
                            type: 'success',
                            duration: 2000,
                            onClose: this.$router.go(-1)
                        })
                    })
                })
            }
        }
    }
</script>

<style>
</style>
